package com.tt.mymu.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Autowired
    private MyInterceptor myInterceptor;
    @Value("${tool.updateFile.img}")
    private String toolUpdateImg;
    @Value("${tool.updateFile.video}")
    private String toolUpdateVideo;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")

                .allowedOriginPatterns("*")
                //.allowedOrigins("http://localhost:8080")
                //.allowedOrigins("*") // 允许任何域进行跨域访问
                .allowedMethods("*")
                .allowedHeaders("*")
                .allowCredentials(true);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myInterceptor)
                .excludePathPatterns("/user/loginUser") // 放行那些url
                .addPathPatterns("/info/selectInfoById");// 拦截的url

    }


}
